package com.dahua.messagesyncbj.thread;

import org.springframework.stereotype.Component;

import java.util.concurrent.*;

@Component
public class ThreadPool {
    /*  核心线程数*/
    int corePoolSize = 5;

    /*  最大线程数*/
    int maxPoolSize = 10;

    /*  空闲核心线程销毁时间*/
    long keepAliveTime = 5000;

    //private static ConcurrentLinkedDeque<Runnable> runnables = new ConcurrentLinkedDeque<>();

    ThreadPoolExecutor executor = new ThreadPoolExecutor(
            corePoolSize,
            maxPoolSize,
            keepAliveTime,
            TimeUnit.MILLISECONDS,
            new LinkedBlockingQueue<Runnable>(),
            Executors.defaultThreadFactory(),
            new ThreadPoolExecutor.CallerRunsPolicy()
    );

    public void execute(Runnable runnable) {
        executor.execute(runnable);
    }
}
